
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:osc/ui/widgets/common_scaffold.dart';
import 'package:osc/ui/widgets/small_widgets.dart';
import 'package:osc/ui/widgets/web_widget.dart';
import 'package:osc/utils/navigator_util.dart';

class WebScaffold extends StatefulWidget {
  const WebScaffold({
    Key key,
    this.title,
    this.url,
    this.autoAddPostfix = true,
  }) : super(key: key);

  final String title;
  final String url;
  final bool autoAddPostfix;

  @override
  State<StatefulWidget> createState() {
    return new WebScaffoldState();
  }
}


class WebScaffoldState extends State<WebScaffold> {
  // On urlChanged stream
  String currentUrl;

  Cookie cookie;

  @override
  void initState() {
    super.initState();

    currentUrl = widget.url;

  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return CommonScaffold(
        title: widget.title ?? "",
        body: WebWidget(
          url: currentUrl,
        ),
        actions: <Widget>[
          SmallWidgets.buildActionIconButton(
              imageName: "ic_action_browser",
              context: context,
            onTap: (){
                NavigatorUtil.launchInBrowser(currentUrl);
            }
          ),
        ],
    );
  }

}